<?php
/**
 * Created by PhpStorm .
 * User: {Administrator}
 * Date: {2022/7/6 16:37}
 * Author: '树叶'
 * Email: 'ayunu@qq.com'
 * Motto Info: '理想如果不向现实做一点点屈服，那么理想也将归于尘土。'
 */

namespace app\api\model;
use think\Db;
use think\Model;

class Integral extends Model
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = '';
    protected $updateTime = '';
    protected $resultSetType = 'collection';
    // 追加属性
    protected $append = [

    ];

    /**
     * 添加积分记录
     * @param $uid 用户ID
     * @param $integral 积分数
     * @param string $type 类型:1=签到,2=分享注册,3=分享商品',
     * @param string $genre 渠道:签到,分享注册,分享商品
     *
     */
    public static function addInteral($uid, $integral, $type = '1', $genre = '签到')
    {

        $data = [
            'uid'       => $uid,
            'integral'  => $integral,
            'type'      => $type,
            'genre'     => $genre,
            'create_time' => time()
        ];
        return Db::name('integral')->insertGetId($data);
    }
}